import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
//import Mock from './mock'
//Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'
import axios from 'axios'
import BaiduMap from 'vue-baidu-map'
Vue.use(BaiduMap, {
  ak: 'DcF7MeZvNZ7q3364YLGW4d8RT9xFn9rk'
})
//axios.defaults.baseURL="http://localhost:8080"
// 后端解决跨域
axios.defaults.baseURL="http://localhost:10030/apis/"
// axios.defaults.baseURL="/api"
Vue.prototype.$http=axios

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

//NProgress.configure({ showSpinner: false });

const router = new VueRouter({
  routes
})
/*
  axios的request拦截器:使用axios发请求,在到达服务器之前都会执行此处的代码
    config:就是当前的请求对象,里面包含了请求头,请求体,请求方式
 */
// axios.interceptors.request.use(config=>{
//
//       //携带请求头
//       if(localStorage.getItem("token")){
//         //携带请求头
//         config.headers.TOKEN=localStorage.getItem("token");
//       }
//       return config;//放行
//     },
//     error => {
//       return Promise.reject(error);
//     });

/*
    axios的响应拦截器
        config:就是当前请求的响应对象
*/

// axios.interceptors.response.use(config=>{
//         console.debug(config)
//         let {data,success,message}=config.data
//         if (!success&& data==="noAuth"){//同时让success和data 作为判断条件
//             //强制跳转到登录页面
//             router.push({ path: '/login' });  // 跳转回登陆页面,让用户登陆
//         }
//         return config;//放行
//     },error => {
//         return Promise.reject(error);
// })

//前置路由

/*router.beforeEach((to, from, next) => {
  //NProgress.start();
  if (to.path == '/login') {
    //前端存储在浏览器离得对象
    localStorage.removeItem('user');
    localStorage.removeItem('token');
  }
  let user = JSON.parse(localStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})*/


//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

